package com.example.reflectdemo.proxy;

import java.lang.reflect.Proxy;

public class DHandlerMain {
    public static void main(String... args){
        Handler handler = new HandlerImpl();

        CostInvocationHandler invocationHandler = new CostInvocationHandler(handler);

        Class cls = Proxy.getProxyClass(DHandlerMain.class.getClassLoader(), Handler.class);

        Handler proxy = (Handler) Proxy.newProxyInstance(DHandlerMain.class.getClassLoader(),
                new Class[]{Handler.class},
                invocationHandler);

        System.out.println("invoke method");
        proxy.handle("Test");
        System.out.println("isProxyClass: " + Proxy.isProxyClass(cls));
        System.out.println("getInvocationHandler: " + (invocationHandler == Proxy.getInvocationHandler(proxy)));
    }
}
